package org.example.everyday;

import java.util.Arrays;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * Copyright: 天津联想协同科技有限公司
 * <p>
 *
 * @author anlu
 * @date 2022/4/22 9:42
 */
public class Lc396 {
    public static void main(String[] args) {
        Lc396 lc396 = new Lc396();
        int[] arr = new int[]{4,3,2,6};
        int res =  lc396.maxRotateFunction(arr);
        System.out.println(res);
    }

    public int maxRotateFunction(int[] nums) {
        int f = 0,n = nums.length, numSum = Arrays.stream(nums).sum();
        for (int i = 0; i < n; i++) {
            f += i * nums[i];
        }
        int res = f;
        for (int i = n - 1; i > 0; i--) {
            f += numSum - n * nums[i];
            res = Math.max(res,f);
        }
        return res;
    }
}
